package com.fuchuang.seckillsystem.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

//公共返回对象
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RespBean {
    
    private Integer code;
    private String message;
    private Object data;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date time;
    private Long timestamp;
    
    //无结果的成功返回
    public static RespBean success() {
        return new RespBean(RespBeanEnum.SUCCESS.getCode(), RespBeanEnum.SUCCESS.getMessage(), null, new Date(), System.currentTimeMillis());
    }
    
    //有结果的成功返回
    public static RespBean success(Object object) {
        return new RespBean(RespBeanEnum.SUCCESS.getCode(), RespBeanEnum.SUCCESS.getMessage(), object, new Date(), System.currentTimeMillis());
    }
    
    //无结果的失败返回
    public static RespBean error(RespBeanEnum respBeanEnum) {
        return new RespBean(respBeanEnum.getCode(), respBeanEnum.getMessage(), null, new Date(), System.currentTimeMillis());
    }
    
    //有结果的失败返回
    public static RespBean error(RespBeanEnum respBeanEnum, Object object) {
        return new RespBean(respBeanEnum.getCode(), respBeanEnum.getMessage(), object, new Date(), System.currentTimeMillis());
    }
}
